﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Code4WP7SDK.Controls
{
    public class NavigateUtilPage : PhoneApplicationPage
    {
        /**
            TestInfo info = obj[0] as TestInfo;
            test.Text = info.name;
         * */
        public virtual void OnPageIn(object[] args) 
        {
            
        }
        
        /**
            TestInfo newInfo=new TestInfo();
            newInfo.name="put an arguemnet of TestInfo: 123435";
            object[] args=new object[1];
            args[0]=newInfo;
            OpenPage("/Page1.xaml", args);
         **/
        public void OpenPage(string url, object[] args)
        {
            BasePageArg basePageArg = new BasePageArg();
            basePageArg.UseData = args;
            string argId = PageManager.PutArgs(basePageArg);
            string navUrl = url + string.Format("?{0}={1}", PageManager.ArgPrev, argId);
            this.NavigationService.Navigate(new Uri(navUrl, UriKind.Relative));
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            BasePageArg basePageArg = PageManager.GetArgOnce(this) as BasePageArg;
            if (basePageArg != null)
            {
                object[] useData = basePageArg.UseData;
                OnPageIn(useData);
            }
        }
    }
}
